<?php

namespace app\cps\controller;

use think\facade\Request;
use app\common\Error;
use app\common\Common;
use app\cps\service\CustomRechargeService;

class CustomRechargeTemplate extends Base
{
    private $service;

    public function __construct(CustomRechargeService $service)
    {
        parent::__construct();
        $this->service = $service;
    }

    // 渲染列表页
    public function index()
    {
        return view();
    }

    // 渲染详情页
    public function info()
    {
        return view();
    }

    /**
     * 新增自定义充值模板
     */
    public function add()
    {
        $params = Request::param();

        try {
            validate(\app\cps\validate\CustomRechargeTemplate::class)->scene('add')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $result = $this->service->addCustomRechargeTemplate($params, $this->getUserInfo());

        if (!empty($result['message'])) {
            return Common::fail($result['message']);
        }
        return Common::success();
    }

    /**
     * 编辑自定义充值模板
     */
    public function edit()
    {
        $params = Request::param();

        try {
            validate(\app\cps\validate\CustomRechargeTemplate::class)->scene('edit')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $result = $this->service->editCustomRechargeTemplate($params, $this->getUserInfo());
        if (!empty($result['message'])) {
            return Common::fail($result['message']);
        }
        return Common::success();
    }
   /**
     * 删除自定义充值模板
     */
    public function delete()
    {
        $params = Request::param();

        try {
            validate(\app\cps\validate\CustomRechargeTemplate::class)->scene('delete')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $result = $this->service->deleteCustomRechargeTemplate($params, $this->getUserInfo());
        if (!empty($result['message'])) {
            return Common::fail($result['message']);
        }
        return Common::success();
    }
    /**
     * 自定义充值模板列表
     */
    public function list()
    {
        $params = Request::param();
        $data = $this->service->customRechargeTemplateList($params, $this->getUserInfo());
        return Common::success($data);
    }

    // 渲染充值设置列表页面
    public function setList()
    {
        return view();
    }

    /**
     * 自定义充值模板详情
     */
    public function detail()
    {
        $params = Request::param();
        $data = $this->service->customRechargeTemplateDetail($params, $this->getUserInfo());
        return Common::success($data);
    }

    // 获取自定义收费设置
    public function select()
    {
        $params = Request::param();
        $data = $this->service->getCustomRechargeTemplateSelect($params, $this->getUserInfo());
        return Common::success($data);
    }

    // 批量收费设置（新版本）
    public function batchRechargeSetting()
    {
        $params = Request::param();
        try {
            validate(\app\cps\validate\CustomRechargeTemplate::class)->scene('batch_recharge_setting')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->batchRechargeSetting($params, $this->getUserInfo());

        if (!empty($data['message'])) {
            return Common::fail($data['message']);
        }

        return Common::success();
    }
}